{
  "properties" : { },
  "id" : "679ace6a76b1435b8a1e75bca28344d7",
  "script" : null,
  "groupId" : "aa81e76ddfd7471a97aa423abd80b2aa",
  "name" : "动态行转列",
  "createTime" : null,
  "updateTime" : 1648029834738,
  "lock" : null,
  "createBy" : "666",
  "updateBy" : "admin",
  "path" : "/pivot",
  "method" : "GET",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 200,\n    \"message\": \"success\",\n    \"data\": {\n        \"2\": 6,\n        \"3\": 4\n    },\n    \"timestamp\": 1648029638473,\n    \"executeTime\": 9\n}",
  "description" : null,
  "requestBodyDefinition" : null,
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "code",
      "value" : "200",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "message",
      "value" : "success",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "Object",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ {
        "name" : "2",
        "value" : "6",
        "description" : "",
        "required" : false,
        "dataType" : "Integer",
        "type" : null,
        "defaultValue" : null,
        "validateType" : "",
        "error" : "",
        "expression" : "",
        "children" : [ ]
      }, {
        "name" : "3",
        "value" : "4",
        "description" : "",
        "required" : false,
        "dataType" : "Integer",
        "type" : null,
        "defaultValue" : null,
        "validateType" : "",
        "error" : "",
        "expression" : "",
        "children" : [ ]
      } ]
    }, {
      "name" : "timestamp",
      "value" : "1648029638473",
      "description" : "",
      "required" : false,
      "dataType" : "Long",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "executeTime",
      "value" : "9",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  }
}
================================
import log;//日志模块
import lombok.extern.slf4j.Slf4j;
import java.util.stream.Collectors;
import java.util.stream.Stream;

var arrres = db.select('select api_method,api_group_id from magic_api_info');
for(a,v in arrres){
    log.info(a+"  "+ v);
}
var arrres2 = arrres.stream().collect(
        Collectors.toMap(
                x -> x.get("api_method").toString(),
                x -> x.get("api_group_id").toString(),
                (v1, v2) -> v1+" "+v2
                // (v1, v2) -> v1
        )
    );
for(key,value in arrres2){    //如果不需要key，也可以写成for(value in map)
    log.info(key + ":" + value);
}

var map2 = {
    key1 : 123,
    key2 : 456
};
for(key,value in map2){    //如果不需要key，也可以写成for(value in map)
    log.info(key + ":" + value);
}

var  arr = [1,2,3];
log.info(arr.toString());

for(a,v in arr){
    log.info(a+"  "+ v);
}
arrres = arrres.stream().collect(Collectors.groupingBy(a->{
    return a.get("api_method");
},Collectors.counting()))
log.info(arrres.toString());
return arrres;

// 期待结果如下
/*
  -     GET    POST 
分组1    X       X
分组2    X       X
分组3    X       X
分组4    X       X
其中X为该分组对应请求方法的数量
*/
// return result.group(it => it.api_group_id,    // 根据api_group_id 分组
//     list => list.group(item => item.api_method, // 根据 请求方法 再次分组
//         apis => apis.size()
//     )
// ).asList((key,value)=>{ // 将分组后的Map<String,Map<String,Object>> 结果转为List<Map<String,Object>
//     ...value,   // 展开Map
//     group_id : key
// })
// //关联分组表,添加分组中文名，此步骤也可以放在SQL中关联。
// .join(db.select('select id,group_name from magic_group'),(t1,t2) => t1.group_id == t2.id)  
// // 移除多余的ID列
// .each(it => it.remove('id')) 